package com.fyx.controller;

import com.fyx.annotation.Log;
import com.fyx.entity.DayDataEntity;
import com.fyx.entity.MonthDataEntity;
import com.fyx.entity.MonthInfo;
import com.fyx.entity.StaticeEntity;
import com.fyx.service.IDayMonthService;
import com.fyx.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@Api(tags = "日报月报")
@RestController
@RequestMapping("/api/dayMonth")
@RequiredArgsConstructor
public class DayMonthController {
    @Autowired
    private IDayMonthService iDayMonthService;




    @Log("查询日报")
    @ApiOperation("查询日报")
    @GetMapping(value = "dayData")
    @PreAuthorize("@el.check('dayData:list')")
    public ResponseEntity<Object> dayData(DayDataEntity dayDataEntity, Pageable pageable){
        Map mapResult = iDayMonthService.dayData(dayDataEntity,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("查询每日广告数")
    @ApiOperation("查询每日广告数")
    @GetMapping(value = "advertDayData")
    @PreAuthorize("@el.check('dayData:list')")
    public ResponseEntity<Object> advertDayData(DayDataEntity dayDataEntity, Pageable pageable){
        Map mapResult = iDayMonthService.advertDayData(dayDataEntity,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("修改穿山甲数量")
    @ApiOperation("修改穿山甲数量")
    @PostMapping(value = "updatePangolin")
    public ResponseEntity<Object> updatePangolin(@Validated @RequestBody StaticeEntity staticeEntity) throws IOException {
        iDayMonthService.updatePangolin(staticeEntity);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("修改优量汇数量")
    @ApiOperation("修改优量汇数量")
    @PostMapping(value = "updateYoulianghui")
    public ResponseEntity<Object> updateYoulianghui(@Validated @RequestBody DayDataEntity dayDataEntity) throws IOException {
        iDayMonthService.updateYoulianghui(dayDataEntity);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("查询月报")
    @ApiOperation("查询月报")
    @GetMapping(value = "monthData")
    @PreAuthorize("@el.check('monthData:list')")
    public ResponseEntity<Object> query(MonthDataEntity monthDataEntity, Pageable pageable){
        Map mapResult = iDayMonthService.monthData(monthDataEntity,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }


    @Log("每月记录")
    @ApiOperation("每月记录")
    @GetMapping(value = "monthInfo")
    @PreAuthorize("@el.check('monthInfo:list')")
    public ResponseEntity<Object> monthInfo(MonthInfo monthInfo, Pageable pageable){
        Map mapResult = iDayMonthService.monthInfo(monthInfo,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }



    /**
     * 获取本月数据
     *
     * @return
     */
    @Log("获取本月数据")
    @ApiOperation("获取本月数据")
    @GetMapping(value = "getCurrentMonthData")
    @ResponseBody
    public ResponseEntity<Object> getCurrentMonthData(){
        iDayMonthService.getCurrentMonthData();
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 获取上月数据
     *
     * @return
     */
    @Log("获取上月数据")
    @ApiOperation("获取上月数据")
    @GetMapping(value = "getLastMonthData")
    @ResponseBody
    public ResponseEntity<Object> getLastMonthData(){
        iDayMonthService.getLastMonthData();
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
